<?php 

if (! getParameter("goodId")!=null){
$search="";
if (getParameter("search")!=null)	$search=getParameter("search");
if (getParameter("searchmode")!=null)	$portlet_goodsearch_searchmode=getParameter("searchmode");

if ($search=="true"){
		?>
		
		
		<?php 
}else{
if ($portlet_goodsearch_searchmode=="basic") {
	?>
<div class="announcementsTitle"><?php echo $text_search_basic; ?></div> 
  <div class="homeTabs">
<form action="<?php echo curPageURI();?>" method="POST">
  <input  type="hidden" name="search" value="true">
 <table cellspacing="0" class="ewTable">
	<tbody>
	
	<tr class="ewTableRow">
	
		<td style="border-right: 0pt none;" colspan="2"><span id="el_operationtypeId">
<div class="ewTemplate" id="tp_operationtypeId"><label></label></div>

<table class="ewItemTable"><tbody><tr>
<?php
$sSql ="Select operationtype.lib_".$lang." as lib, operationtype.id From immo_operationtype operationtype ";
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
		  ?>
<td><label><input type="radio" <?php if ($rs->fields["id"]==1) echo "checked='checked' "; ?> value="<?php echo $rs->fields["id"]; ?>" title=""  name="operationtypeId"><?php echo $rs->fields["lib"]; ?></label></td>


				  <?php
		  $rs->MoveNext();    
		  }


	
?>
<td>&nbsp;</td></tr></tbody></table>
</span>		</td>
	</tr>
	
	

	<tr class="ewTableAltRow">
		<td class="pam_title" style="padding-top: 11px;"><?php echo $text_search_budget; ?></td>
		<td style="border-right: 0pt none;">

<table>
<tr>
<td>
<div id="slider-amount" style="width: 197px;"></div>
</td>
<td style="padding-top: 14px;">

	<input type="hidden" name="price_min" id="price_min" />
	<input type="hidden" name="price_max" id="price_max" />
	<input type="text" id="amount"  />

</td>

</tr>
</table>






	</td>
	</tr>
	
	<tr class="ewTableRow">
		<td class="pam_title" style="padding-top: 11px;"><?php echo $text_request_rooms; ?></td>
		<td style="border-right: 0pt none;"><span id="el_rooms">
<table>
<tr>
<td>
<div id="slider-rooms" style="width: 197px;"></div>
</td>
<td style="padding-top: 14px;">

	<input type="hidden" name="rooms_min" id="rooms_min" />
	<input type="hidden" name="rooms_max" id="rooms_max" />
	<input type="text" id="rooms"  />

</td>

</tr>
</table>
</span>		</td>
	</tr>

	
	<tr class="ewTableAltRow"  <?php if ($international=="N") { ?>style="display: none"<?php } ?>>
		<td class="pam_title"><?php echo $text_request_country; ?></td>
		<td style="border-right: 0pt none;"><span id="el_countryId">
		

<select  title="" name="countryId" id="countryId">
<option value="none"><?php echo $choisir; ?></option>
<?php

$sSql ="Select countries.lib_".$lt." as lib, countries.id From portal_countries countries ";
if ($international=="N") $sSql.="WHERE countries.id=".$defaultCountry;
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
 	
		  ?>
<option  value="<?php echo $rs->fields["id"]; ?>"><?php echo $rs->fields["lib"]; ?></option>

				  <?php
		  $rs->MoveNext();    
		  }


	
?>
</select>	
</td>
	</tr>
		<tr class="ewTableAltRow" >
		<td class="pam_title"><?php echo $text_request_city; ?></td>
		<td style="border-right: 0pt none;"><span id="el_cityId">	
		
<select  name="cityId" id="cityId" >
</select>
</span>		</td>
	</tr>
	



</tbody></table>
<input type="submit" value="<?php echo $text_search; ?>"> 
 <input type="button" value="<?php echo $text_search_button_advanced; ?>" onclick="location.href='<?php echo createUrl("searchmode","advanced"); ?>';"> 
 </form>
	
	
	

	
	
	<!--  	<a href="<?php echo createUrl("searchmode","advanced"); ?>"><?php echo $text_search_advanced; ?></a>-->
		</div>
	<?php 
	
}elseif ($portlet_goodsearch_searchmode=="advanced") {
	
?>
<div class="announcementsTitle"><?php echo $text_search_advanced; ?></div> 

  <div class="homeTabs">
<form action="<?php echo curPageURI();?>" method="POST">
  <input  type="hidden" name="search" value="true">
 <table cellspacing="0" class="ewTable">
	<tbody>
	<tr class="ewTableAltRow">
		<td class="pam_title"><?php echo $text_request_goodtype; ?><span class="ewRequired">&nbsp;*</span></td>
		<td style="border-right: 0pt none;"><span id="el_goodtypeId">
<table class="ewItemTable"><tbody><tr>

<?php
$sSql ="Select goodtype.lib_".$lang." as lib, goodtype.id From immo_goodtype goodtype ";
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
		  ?>
<td><label><input type="checkbox"  value="<?php echo $rs->fields["id"]; ?>" title="" name="goodtypeId"><?php echo $rs->fields["lib"]; ?></label></td>
				  <?php
		  $rs->MoveNext();    
		  }


	
?>
<td>&nbsp;</td></tr></tbody></table>
</span>		</td>
	</tr>
	<tr class="ewTableRow">
	
		<td style="border-right: 0pt none;" colspan="2"><span id="el_operationtypeId">
<div class="ewTemplate" id="tp_operationtypeId"><label></label></div>

<table class="ewItemTable"><tbody><tr>
<?php
$sSql ="Select operationtype.lib_".$lang." as lib, operationtype.id From immo_operationtype operationtype ";
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
		  ?>
<td><label><input type="radio" <?php if ($rs->fields["id"]==1) echo "checked='checked' "; ?> value="<?php echo $rs->fields["id"]; ?>" title=""  name="operationtypeId"><?php echo $rs->fields["lib"]; ?></label></td>


				  <?php
		  $rs->MoveNext();    
		  }


	
?>
<td>&nbsp;</td></tr></tbody></table>
</span>		</td>
	</tr>
	
	

	<tr class="ewTableAltRow">
		<td class="pam_title" style="padding-top: 11px;"><?php echo $text_search_budget; ?></td>
		<td style="border-right: 0pt none;">

<table>
<tr>
<td>
<div id="slider-amount" style="width: 197px;"></div>
</td>
<td style="padding-top: 14px;">

	
	<input type="text" id="amount"  />

</td>

</tr>
</table>






	</td>
	</tr>
	
	<tr class="ewTableRow">
		<td class="pam_title" style="padding-top: 11px;"><?php echo $text_request_rooms; ?></td>
		<td style="border-right: 0pt none;"><span id="el_rooms">
<table>
<tr>
<td>
<div id="slider-rooms" style="width: 197px;"></div>
</td>
<td style="padding-top: 14px;">

		<input type="hidden" name="rooms_min" id="rooms_min" />
	<input type="hidden" name="rooms_max" id="rooms_max" />
	<input type="text" id="rooms"  />

</td>

</tr>
</table>
</span>		</td>
	</tr>
	
	

	
	<tr class="ewTableRow">
		<td class="pam_title" style="padding-top: 11px;"><?php echo $text_request_surface; ?></td>
		<td style="border-right: 0pt none;"><span id="el_surface">
<table>
<tr>
<td>
<div id="slider-surface" style="width: 197px;"></div>
</td>
<td style="padding-top: 14px;">

		<input type="hidden" name="surface_min" id="surface_min" />
	<input type="hidden" name="surface_max" id="surface_max" />
	<input type="text" id="surface"  />

</td>

</tr>
</table>
</span>		</td>
	</tr>


	
	<tr class="ewTableRow"  <?php if ($international=="N") { ?>style="display: none"<?php } ?>>
		<td class="pam_title"><?php echo $text_request_country; ?><span class="ewRequired">&nbsp;*</span></td>
		<td style="border-right: 0pt none;"><span id="el_countryId">
		
<select  title="" name="countryId" id="countryId" >
<option value="none"><?php echo $choisir; ?></option>
<?php

$sSql ="Select countries.lib_".$lt." as lib, countries.id From portal_countries countries ";
if ($international=="N") $sSql.="WHERE countries.id=".$defaultCountry;
      $rs=$GLOBALS["conn"]->Execute($sSql); 
		
 while ( !$rs->EOF)  { 
 	
		  ?>
<option  value="<?php echo $rs->fields["id"]; ?>"><?php echo $rs->fields["lib"]; ?></option>

				  <?php
		  $rs->MoveNext();    
		  }


	
?>
</select>
</span>		</td>
	</tr>
	<tr class="ewTableAltRow">
		<td class="pam_title"><?php echo $text_request_city; ?><span class="ewRequired">&nbsp;*</span></td>
		<td style="border-right: 0pt none;"><span id="el_cityId">
<select  name="cityId" id="cityId" >
<option value="none"><?php echo $choisir; ?></option>
</select>
</span>		</td>
	</tr>
	<tr class="ewTableRow">
		<td class="pam_title"><?php echo $text_request_quarter; ?><span class="ewRequired">&nbsp;*</span></td>
		<td style="border-right: 0pt none;"><span id="el_quartierId">
<select title="" name="quartierId" id="quartierId" >
<option value="none"><?php echo $choisir; ?></option>
</select>
<input type="hidden" value="Rif1MfTdAs1M1ttxTU6oWueefnFbVEmGEao4rpu5vDc80M0aibnTXydP_kWsQc7vdi4fExcoP6qmcNws74gh1zsTamrbJ_VSvedz8mOpQ6a5EdoCMy1-JL3YigH9iXG85zZnV-Zy6iu3AKoCSXHGAw.." id="s_quartierId" name="s_quartierId">
<input type="hidden" value="1" id="lft_quartierId" name="lft_quartierId">
</span>		
</td>
	</tr>



</tbody></table>
<input type="submit" value="<?php echo $text_search; ?>"> 
 <input type="button" value="<?php echo $text_search_button_basic; ?>" onclick="location.href='<?php echo createUrl("searchmode","basic"); ?>';"> 
 </form>
<!-- <a href="<?php echo createUrl("searchmode","basic"); ?>"><?php echo $text_search_basic; ?></a> -->
  </div>

<?php }} ?>

<script type="text/javascript" charset="utf-8">


$("select#countryId").change(function(){
    $.getJSON("portlet.php",{id: $(this).val(),app:'citiesajax',language:'<?php echo $lt; ?>', ajax: 'true'}, function(data){
   	      
        var options = '<option value="none"><?php echo $choisir; ?></option>';
    for (var i = 0; i < data.length; i++) {
        options += '<option value="' +data[i].optionValue + '">' + data[i].optionDisplay + '</option>';
      }
      $("select#cityId").html(options);
     
      $("select#cityId").val(<?php echo $defaultCity; ?>);
 	 $("select#cityId").change();

      
    })
  })



  $("select#cityId").change(function(){
    $.getJSON("portlet.php",{id: $(this).val(),app:'quartiersajax',language:'<?php echo $lt; ?>', ajax: 'true'}, function(data){

   	      
        var options = '<option value="none"><?php echo $choisir; ?></option>';
    for (var i = 0; i < data.length; i++) {
        options += '<option value="' +data[i].optionValue + '">' + data[i].optionDisplay + '</option>';
      }
      $("select#quartierId").html(options);

      
    })
  })

	$(document).ready(function() {
 $("select#countryId").val("<?php echo $defaultCountry; ?>");
 $("select#countryId").change();
	});




	$("input[name='operationtypeId']").change(function() {
		 if ($(this).val()==2) fac=100; else 
			 if ($(this).val()==4)  fac=3; else fac=10;
		
				$( "#slider-amount" ).slider({
					range: true,
					min: 0*fac,
					max: 200*fac,
					values: [ 20*fac, 70*fac ],
					slide: function( event, ui ) {
						$( "#amount" ).val( formatCurrency(ui.values[ 0 ]*fac) + " <?php echo $text_dhs; ?> - " + formatCurrency(ui.values[ 1 ]*fac) +  " <?php echo $text_dhs; ?> "  );
						$( "#price_max" ).val(ui.values[ 1 ]*fac);
						$( "#price_min" ).val(ui.values[ 0 ]*fac);
						
					}
				});
				//
				
	});
	
	$("input[name='operationtypeId']:checked").change();

	<?php  if ($mode=="show") { ?>
	
	$( "#amount" ).val( $( "#slider-amount" ).slider( "values", 0 )*fac + " <?php echo $text_dhs; ?> - " + $( "#slider-amount" ).slider( "values", 1 )*fac+  " <?php echo $text_dhs; ?> "  );
	$( "#price_max" ).val($( "#slider-amount" ).slider( "values",1 )*fac);
	$( "#price_min" ).val($( "#slider-amount" ).slider( "values", 0 )*fac);
	<?php } ?>
	
	$( "#slider-rooms" ).slider({
		range: true,
		min: 1,
		max: 10,
		values: [ 2, 5 ],
		slide: function( event, ui ) {
			$( "#rooms" ).val(ui.values[ 0 ] + " <?php echo $text_rooms; ?> - " + ui.values[ 1 ] +  " <?php echo $text_rooms; ?> "  );
			$( "#rooms_max" ).val(ui.values[ 1 ]);
			$( "#rooms_min" ).val(ui.values[ 0 ]);
		}
	});
	$( "#rooms" ).val( $( "#slider-rooms" ).slider( "values", 0 )+ " <?php echo $text_rooms; ?> - " + $( "#slider-rooms" ).slider( "values", 1 )+  " <?php echo $text_rooms; ?> "  );
	$( "#rooms_max" ).val($( "#slider-rooms" ).slider( "values", 1 ));
	$( "#rooms_min" ).val($( "#slider-rooms" ).slider( "values", 0 ));
	
	$( "#slider-surface" ).slider({
		range: true,
		min: 10,
		max: 3000,
		values: [ 600, 1500 ],
		slide: function( event, ui ) {
			$( "#surface" ).val(ui.values[ 0 ] + " <?php echo $text_surface; ?> - " + ui.values[ 1 ] +  " <?php echo $text_surface; ?> "  );
			$( "#surface_max" ).val(ui.values[ 1 ]);
			$( "#surface_min" ).val(ui.values[ 0 ]);
		}
	});
	$( "#surface" ).val( $( "#slider-surface" ).slider( "values", 0 )+ " <?php echo $text_surface; ?> - " + $( "#slider-surface" ).slider( "values", 1 )+  " <?php echo $text_surface; ?> "  );
	$( "#surface_max" ).val($( "#slider-surface" ).slider( "values", 1 ));
	$( "#surface_min" ).val($( "#slider-surface" ).slider( "values", 0 ));
	</script>
		<style>
	
	
	#amount{
	border:0; 
	width: 297px;
	padding-<?php echo $left; ?>: 10px;
 background-color: transparent;
	}
	#rooms{
	border:0; 
	width: 297px;
	padding-<?php echo $left; ?>: 10px;
 background-color: transparent;
	}
	#surface{
	border:0; 
	width: 297px;
	padding-<?php echo $left; ?>: 10px;
 background-color: transparent;
	}
	</style>
<?php } ?>	